package at.fhj.pse.pageobjects;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class LoginPage
{
	private WebDriver driver;
	private String baseUrl;

	/*
	 * Constructor
	 */
	public LoginPage(WebDriver driver, String baseUrl, int timeout)
	{
		this.driver = driver;
		this.baseUrl = baseUrl;
		driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
	}

	public LoginPage(WebDriver driver2) {
		this.driver = driver2;
	}


	/*
	 * Input field: username:String
	 */
	private String username;
	public String getUsername()
	{
		return username;
	}
	public void setUsername(String username)
	{
		this.username = username;
	}


	/*
	 * Input field: password:String
	 */
	private String password;
	public String getPassword()
	{
		return password;
	}
	public void setPassword(String password)
	{
		this.password = password;
	}


	/*
	 * Action: Login
	 */
	public WelcomePage login()
	{
		driver.get(baseUrl);
		driver.findElement(By.id("loginForm:username")).clear();
		driver.findElement(By.id("loginForm:username")).sendKeys(getUsername());
		driver.findElement(By.id("loginForm:password")).clear();
		driver.findElement(By.id("loginForm:password")).sendKeys(getPassword());
		driver.findElement(By.id("loginForm:login")).click();

		return new WelcomePage(driver);
	}


	/*
	 *  Method: getLoggedOutStatus
	 */
	public String getLoggedOutStatus()
	{
		return driver.findElement(By.xpath("/html/body/div[1]/header/div")).getText();
	}
}
